<PlausibleWeb.Components.FlowProgress.render flow={@flow} current_step="Add site info" />

<.focus_box>
  <:title>
    Add website info
  </:title>

  <.form :let={f} for={@changeset} action={@form_submit_url}>
    <PlausibleWeb.Components.Billing.Notice.limit_exceeded
      :if={@site_limit_exceeded?}
      current_role={@current_team_role}
      current_team={@current_team}
      limit={@site_limit}
      resource="sites"
    />

    <div class="my-6">
      <.input
        help_text="Just the naked domain or subdomain without 'www', 'https' etc."
        type="text"
        placeholder="example.com"
        field={f[:domain]}
        label="Domain"
        disabled={@site_limit_exceeded?}
      />
    </div>
    <div class="my-6">
      <.input
        type="select"
        help_text="To make sure we agree on what 'today' means"
        field={f[:timezone]}
        id="tz-select"
        value="Etc/Greenwich"
        disabled={@site_limit_exceeded?}
        label="Reporting Timezone"
        options={Plausible.Timezones.options()}
      />
    </div>
    <script>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 var option;

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 if (typeof Intl !== "undefined") {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   var timezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     option = document.querySelector('#tz-select option[value="' + timezoneName + '"]')
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 }

      if (!option) {
        var offset = (new Date()).getTimezoneOffset()
          option = document.querySelector('#tz-select option[offset="' + offset + '"]')
      }

      if (option) { option.selected = "selected"}
    </script>

    <.button
      disabled={@site_limit_exceeded?}
      type="submit"
      class="w-full disabled:cursor-not-allowed"
    >
      Install Plausible
    </.button>
  </.form>
</.focus_box>
